#include <iostream>
using namespace std;

// 65.45 %
class Solution
{
  public:
	int romanToInt(string s)
	{
		if (s.length() <= 1)
			return charToInt(s[0]);
		int res = charToInt(s[0]);
		for (int i = 1; i < s.length(); i++)
		{
			if (charToInt(s[i]) > charToInt(s[i - 1]))
				res = res + charToInt(s[i]) - 2 * charToInt(s[i - 1]);
			else
				res += charToInt(s[i]);
		}
		return res;
	}
	int charToInt(char s)
	{
		switch (s)
		{
		case 'I':
			return 1;
		case 'V':
			return 5;
		case 'X':
			return 10;
		case 'L':
			return 50;
		case 'C':
			return 100;
		case 'D':
			return 500;
		case 'M':
			return 1000;
		default:
			return 0;
		}
	}
};

int main()
{
	string s = "IV";
	cout << Solution().romanToInt(s) << endl;
	return 0;
}
